﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Core;


namespace Entity.Admin
{
    [MetadataType(typeof(MenuMetadate))]
    public partial class Menu : ITree<Menu>, ITree
    {
        public class MenuMetadate
        {
            [HiddenInput(DisplayValue = false)]
            public string ID { get; set; }

            [Required]
            [Display(Name = "名称", Order = 1)]
            public string MenuText { get; set; }

            [Display(Name = "区域名称", Order = 2)]
            public string Area { get; set; }

            [Display(Name = "控制器名称", Description = "控制器的描述", Order = 3)]
            public string Controller { get; set; }

            [Display(Name = "方法名称", Order = 4)]
            public string Action { get; set; }

            [Display(Name = "启用", Order = 13)]
            public bool Enable { get; set; }

            [Display(Name = "父菜单", Order = 0)]
            //[HiddenInput(DisplayValue = false)]
            [DropDownList("Menus", "ID", "MenuText", "请选择")]
            public string ParentID { get; set; }

            [Display(Name = "显示顺序", Description = "显示顺序的描述", Order = 6)]
            [HiddenInput(DisplayValue = false)]
            public int OrderIndex { get; set; }

            [Display(Name = "是否校验访问权限", Order = 14)]
            public bool CheckRight { get; set; }

            [Display(Name = "目标地址ID", Order = 9)]
            public string Target { get; set; }

            [Display(Name = "参数", Order = 8)]
            public string Parms { get; set; }

            [Display(Name = "小图标地址", Order = 11)]
            public string SmallImageName { get; set; }

            [Display(Name = "大图标地址", Order = 12)]
            public string LargeImageName { get; set; }

            [ScaffoldColumn(false)]
            public int Layer { get; set; }
        }

        public int Layer
        {
            get
            {
                int _layer = 1;
                var _parent = Parent;
                if (_parent == null)
                {
                    return _layer;
                }
                else
                {
                    while (_parent != null)
                    {
                        _layer++;
                        _parent = _parent.Parent;
                    }
                    return _layer;
                }
                //throw new NotImplementedException();
            }
        }
    }
}
